// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   URLImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;
import com.sunwayhorizo.health.hl7.datatypes.URL;

// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, NullFlavorImpl, 
//            STImpl, TYPEImpl

public class URLImpl extends ANYImpl
    implements URL
{

    public static final String RCS_ID = "$Header: URLImpl.java 115.25 2005/09/16 09:24:04 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: URLImpl.java 115.25 2005/09/16 09:24:04 amchanda noship $", "oracle.apps.ctb.hl7.types");
    protected static final String URL_SEPARATOR = ":";
    private CS mScheme;
    private ST mAddress;
    private static final URL nullNI = new URLImpl(CSImpl.valueOf("NI"));
    private static final URL nullOTH = new URLImpl(CSImpl.valueOf("OTH"));
    private static final URL nullNINF = new URLImpl(CSImpl.valueOf("NINF"));
    private static final URL nullPINF = new URLImpl(CSImpl.valueOf("PINF"));
    private static final URL nullUNK = new URLImpl(CSImpl.valueOf("UNK"));
    private static final URL nullASKU = new URLImpl(CSImpl.valueOf("ASKU"));
    private static final URL nullNAV = new URLImpl(CSImpl.valueOf("NAV"));
    private static final URL nullMSK = new URLImpl(CSImpl.valueOf("MSK"));
    private static final URL nullNA = new URLImpl(CSImpl.valueOf("NA"));
    private static final URL nullNASK = new URLImpl(CSImpl.valueOf("NASK"));

    public static URL valueOf(CS cs, ST st)
    {
        return new URLImpl(cs, st);
    }

    public static URL valueOf(String s, String s1)
    {
        CS cs = CSImpl.valueOf(s);
        ST st = STImpl.valueOf(s1);
        return valueOf(cs, st);
    }

    public static URL nullURL()
    {
        return new URLImpl(null);
    }

    protected URLImpl(CS cs, ST st)
    {
        mScheme = cs;
        mAddress = st;
    }

    protected URLImpl(CS cs)
    {
        super(true, cs);
        mScheme = CSImpl.nullCS(NullFlavorImpl.NI);
        mAddress = STImpl.nullST(NullFlavorImpl.NI);
    }

    public CS scheme()
    {
        if(isNull().isTrue())
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return mScheme;
    }

    public ST address()
    {
        if(isNull().isTrue())
            return STImpl.nullST(NullFlavorImpl.NI);
        else
            return mAddress;
    }

    public ST literal()
    {
        
        
        
        if(isNull().isTrue())
        {
            return STImpl.nullST(NullFlavorImpl.NI);
        } else
        {
            String s = mScheme.literal().stringValue();
            String s1 = mAddress.stringValue();
            StringBuffer stringbuffer = new StringBuffer();
            stringbuffer.append(s);
            stringbuffer.append(":");
            stringbuffer.append(s1);
            return STImpl.valueOf(stringbuffer.toString());
        }
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.URL;
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
        {
            i = 37 * i + scheme().hashCode();
            i = 37 * i + (address() != null ? address().hashCode() : 0);
        }
        return i;
    }

    public BL equal(ANY any)
    {
        if(any instanceof URL)
        {
            if(isNull().or(any.isNull()).isTrue())
            {
                return BLImpl.FALSE;
            } else
            {
                URL url = (URL)any;
                return mScheme.equal(url.scheme()).or(mScheme.isNull().and(url.scheme().isNull())).and(mAddress.equal(url.address()).or(mAddress.isNull().and(url.address().isNull())));
            }
        } else
        {
            return BLImpl.FALSE;
        }
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLAttr xmlattr = (XMLAttr)xmldocument.createAttribute(s);
//            xmlattr.setNodeValue(scheme().code().stringValue() + ":" + address().stringValue());
//            return (new XMLNode[] {
//                xmlattr
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static URL nullURL(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
